<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
    <title>ShellCheck: SC1003 – Want to escape a single quote? `echo 'This is how it'\''s done'`.</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
  </head>
  <body style="margin-left: auto; margin-right: auto; max-width: 800px">
    <h1>SC1003 – ShellCheck Wiki</h1>
    <a href="https://github.com/koalaman/shellcheck/wiki/SC1003">See this page on GitHub</a>
    <p style="display: none"><a href="index.html">Sitemap</a></p>
    <hr />
    <h2 id="want-to-escape-a-single-quote-echo-this-is-how-its-done">Want to
escape a single quote?
<code>echo 'This is how it'\''s done'</code>.</h2>
<p>(Note: in v0.4.6, the error message was accidentally missing the
backslash)</p>
<h3 id="problematic-code">Problematic code:</h3>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="SC1003.html#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="bu">echo</span> <span class="st">&#39;This is not how it\&#39;</span>s done<span class="st">&#39;.</span></span></code></pre></div>
<h3 id="correct-code">Correct code:</h3>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="SC1003.html#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="bu">echo</span> <span class="st">&#39;This is how it&#39;</span><span class="dt">\&#39;</span><span class="st">&#39;s done&#39;</span>.</span></code></pre></div>
<h3 id="rationale">Rationale</h3>
<p>In POSIX shell, the shell cares about nothing but another
single-quote to terminate the quoted segment. Not even backslashes are
interpreted.</p>
<p><a
href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_02">POSIX.1
Shell Command Language § 2.2.2 Single Quotes</a>:</p>
<blockquote>
<p>Enclosing characters in single-quotes ( <code>''</code> ) shall
preserve the literal value of each character within the single-quotes. A
single-quote cannot occur within single-quotes.</p>
</blockquote>
<h3 id="exceptions">Exceptions</h3>
<p>If you want your single-quoted string to end in a backslash, you can
rewrite as <code>'string'\\</code> or <a href="ignore.html">ignore</a> this
warning.</p>
    <hr />
    <p style='font-size: 80%'><a href="../index.html">ShellCheck</a> is a static analysis tool for shell scripts. This page is part of its documentation.</p>
  </body>
</html>


